package com.interagriculture.controller;

import com.interagriculture.annotation.AdminVerify;
import com.interagriculture.common.PageResult;
import com.interagriculture.common.Result;
import com.interagriculture.entity.Honor;
import com.interagriculture.mapper.HonorMapper;
import com.interagriculture.service.HonorService;
import javafx.beans.DefaultProperty;
import javafx.scene.paint.PhongMaterial;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.List;

/**
 * 荣誉奖项的响应数据
 */
@RestController
@Slf4j
@RequestMapping("/honor")
public class HonorController {

    @Autowired
    private HonorService honorService;
    /**
     * 分页获取荣誉奖项,并且分页展示
     */
    @GetMapping("/get")
    public Result<PageResult> getHonors(@RequestBody(required = false) Honor honor,
                                        @RequestParam(defaultValue = "1") Integer pageNum,
                                        @RequestParam(defaultValue = "100") Integer pageSize){
        log.info("根据条件查询荣誉奖项,{},{},{}",honor,pageNum,pageSize);
        PageResult pageResult = honorService.getHonors(honor,pageNum,pageSize);
        return Result.ok(pageResult);
    }

    /**
     *  荣誉的增与改
     */
    @AdminVerify
    @PostMapping("/saveOrUpdateInfo")
    public Result saveOrUpdateInfo(@RequestBody Honor honor){
        log.info("荣誉的增改,{}",honor);
        honorService.saveOrUpdateInfo(honor);
        return Result.ok();
    }

    /**
     * 荣誉的删除
     */
    @AdminVerify
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        log.info("删除荣誉项,id:{}",id);
        honorService.delete(id);
        return Result.ok();

    }

}
